package org.wsff.tools.api.gateway.manager;

import org.wsff.tools.api.gateway.error.GatewayException;

/**
 * 组件生命周期管理
 * 
 * @author ryan
 * @version Id: Lifecycle.java, v 0.1 2022-01-19 18:23 ryan Exp $$
 */
public interface Lifecycle extends Ordered, Comparable<Lifecycle> {

    /**
     * 开始
     *
     * @throws GatewayException 异常
     */
    void start() throws GatewayException;

    /**
     * 销毁
     *
     * @throws GatewayException 异常
     */
    void destroy() throws GatewayException;

    /**
     * Compares this object with the specified object for order.  Returns a
     * negative integer, zero, or a positive integer as this object is less
     * than, equal to, or greater than the specified object.
     */
    @Override
    default int compareTo(Lifecycle o) {
        if (o == null) {
            throw new IllegalArgumentException();
        }
        return Integer.compare(this.order(), o.order());
    }

    /**
     * 顺序
     *
     * @return 顺序
     */
    @Override
    default int order() {
        return MIN;
    };
}
